<?php 
    
    class Orange_Customizer {
        public static function register($wp_customize) {
            // set logo
            $wp_customize->add_section(
                'logo_options', 
                array(
                    'title'       => __( 'Logo Setting', 'orange' ),
                    'priority'    => 1000,
                    'capability'  => 'edit_theme_options',
                    'description' => __('Change you logo here.', 'orange'), 
                ) 
            );

            $wp_customize->add_setting( 'orange_logo',
                array(
                    'sanitize_callback' => 'esc_url_raw',
                    'transport' => 'postMessage'
                )
            );

            $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, 'orange_logo',
                array(
                    'label'    => __( 'Logo setting', 'orange' ), 
                    'section'  => 'logo_options',
                    'settings' => 'orange_logo',
                    'priority' => 10,
                ) 
            ));

            // bg color options
            $wp_customize->add_section( 
                'color_options', 
                array(
                    'title'       => __( 'Background Color Settings', 'orange' ),
                    'priority'    => 1001,
                    'capability'  => 'edit_theme_options',
                    'description' => __('Change footer bg-color options here.', 'orange'), 
                ) 
            );
            // footer bg color
            $wp_customize->add_setting( 'footer_bg_color',
                array(
                    'default' => '123466',
                    'transport' => 'postMessage'
                )
            );

            $wp_customize->add_control( new WP_Customize_Color_Control(
                $wp_customize, 
                'footer_bg_color_control',
                array(
                    'label'    => __( 'Footer Background Color', 'orange' ), 
                    'section'  => 'color_options',
                    'settings' => 'footer_bg_color',
                    'priority' => 10,
                ) 
            ));
            // cooperation bg color
            $wp_customize->add_setting( 'cooperation_bg_color',
                array(
                    'default' => 'f1f1f1',
                    'transport' => 'postMessage'
                )
            );
            $wp_customize->add_control( new WP_Customize_Color_Control(
                $wp_customize,
                'cooperation_bg_color_control',
                array(
                    'label'    => __( 'Cooperation Background Color', 'orange' ), 
                    'section'  => 'color_options',
                    'settings' => 'cooperation_bg_color',
                    'priority' => 10,
                ) 
            ) );
        }
        public static function header_output() {
            ?>
                <style type='text/css'>
                    footer {
                        background-color:<?php echo get_theme_mod('footer_bg_color') ?> ;
                    }
                    .cooperation{
                        background-color:<?php echo get_theme_mod('cooperation_bg_color'); ?>
                    }
                </style>
            <?php
        }
        public static function live_preview() {
            wp_enqueue_script('orange_theme_customizer',get_template_directory_uri().'/scripts/theme-customizer.js', ['jquery', 'customize-preview'],'1.0',true);
        }
    }

    add_action( 'customize_register' , array( 'Orange_Customizer' , 'register' ) );
    add_action( 'wp_head' , array( 'Orange_Customizer' , 'header_output' ) );
    add_action( 'customize_preview_init' , array( 'Orange_Customizer' , 'live_preview' ) );

